// 懒加载方法
import React from 'react';
import { ActivityIndicator } from 'antd-mobile';

const lazyLoad = importComponent => {
   return class extends React.Component {
      constructor() {
         super();
         this.state = {
            component: null
         };
      }

      componentDidMount() {
         importComponent().then(cmp => {
            this.setState({ component: cmp.default });
         });
          window.scrollTo(0, 0);
      }

      render() {
         const Cfun = this.state.component;
         return Cfun ? <Cfun {...this.props} /> : <div style={{ background: 'white', display: 'flex', justifyContent: 'center', alignContent: 'center', width: '100vw', height: '100vh' }}><ActivityIndicator true size="large"></ActivityIndicator></div>;
      }
   }
}

export default lazyLoad;
